/**
 * Created with JetBrains PhpStorm.
 * User: ishowshao
 * Date: 12-12-11
 * Time: 上午12:22
 * To change this template use File | Settings | File Templates.
 */
jQuery.get('is-login.php?' + new Date(), function (result) {
    var md5 = function (string) {
        return string;
    };
    var loadMain = function () {
        Candy.loadScript('js/index.js');
    };
    var loginForm = '<form id="login-form" method="post" action="login.php"> <label> <input type="password" name="password" required="required" placeholder="Password"> </label> <label> <input type="submit" name="submit" value="Login"> </label> </form>';
    if (result.success) {
        loadMain();
    } else {
        jQuery('body').append(loginForm);
        jQuery('#login-form').find('input[type=submit]').click(function (e) {
            e.preventDefault();
            jQuery.ajax({
                url: 'login.php',
                type: 'POST',
                data: {
                    password: md5(jQuery('#login-form').find('input[type=password]').val())
                },
                dataType: 'json',
                success: function (result) {
                    if (result.success) {
                        jQuery('#login-form').hide();
                        loadMain();
                    } else {
                        alert('Wrong Password');
                    }
                }
            });
        });
        jQuery('input[type=password]').focus();
    }
}, 'json');
